/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.db;


import cz.muni.fi.pb138.BiographyServlet;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.StringWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Vitek
 */
public class XSLTProcessor {
    
    public void generate(String cv) 
            throws TransformerConfigurationException, TransformerException {

        TransformerFactory tf = TransformerFactory.newInstance();
        File file;
        
        try {
        file = new File(BiographyServlet.PROJECT_PATH + "\\src\\java\\cz\\muni\\fi\\pb138\\db\\test.xml");
        FileWriter wr = new FileWriter(file);
        wr.write(cv);
        wr.flush();
        wr.close();
        
        } catch (Exception e) {
            throw new TransformerException(e);
        }
        
        System.out.println(tf.getClass());
        
        Transformer xsltProc = tf.newTransformer(
                new StreamSource(new File(BiographyServlet.PROJECT_PATH +  "\\src\\java\\cz\\muni\\fi\\pb138\\db\\cv-to-latex.xsl")));
        
        xsltProc.transform(
                new StreamSource(file), 
                new StreamResult(new File(BiographyServlet.PROJECT_PATH + "\\src\\java\\cz\\muni\\fi\\pb138\\db\\cv.tex")));
        file.delete();
    }

    public XSLTProcessor() {
    }
}